﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace SmartPaginator
{
    public static class GeometryExtensions
    {
        #region Size Methods

        public static Size Subtract(this Size size, Thickness thickness)
        {
            double width = Math.Max(0, size.Width - thickness.Left - thickness.Right);
            double height = Math.Max(0, size.Height - thickness.Top - thickness.Bottom);

            return new Size(width, height);
        }

        public static Size Add(this Size size, Thickness thickness)
        {
            double width = Math.Max(0, size.Width + thickness.Left + thickness.Right);
            double height = Math.Max(0, size.Height + thickness.Top + thickness.Bottom);

            return new Size(width, height);
        }

        #endregion

        #region Rect Methods

        public static Rect Add(this Rect rect, Thickness thickness)
        {
            double left = rect.Left - thickness.Left;
            double top = rect.Top - thickness.Top;

            return new Rect(new Point(left, top), rect.Size.Add(thickness));
        }

        public static Rect Subtract(this Rect rect, Thickness thickness)
        {
            double left = rect.Left + thickness.Left;
            double top = rect.Top + thickness.Top;

            return new Rect(new Point(left, top), rect.Size.Subtract(thickness));
        }

        public static Thickness Subtract(this Rect outerRect, Rect innerRect)
        {
            double left = innerRect.Left - outerRect.Left;
            double right = outerRect.Right - innerRect.Right;
            double top = innerRect.Top - outerRect.Top;
            double bottom = outerRect.Bottom - innerRect.Bottom;

            return new Thickness(left, top, right, bottom);
        }

        #endregion
    }
}
